%% B
x =-5:0.001:5;
y=0.0384615+0.192308.*(x-(-5))-0.038462.*(x-(-5)).*(x-(0));
plot(x,y);
hold on;


y=0.0384615+0.039788.*(x-(-5))+0.061008.*(x-(-5)).*(x-(-2.5))-0.026525.*(x-(-5)).*(x-(-2.5)).*(x-(0))+0.005305.*(x-(-5)).*(x-(-2.5)).*(x-(0)).*(x-(2.5));
plot(x,y);
hold on;

y=0.0384615+0.026464.*(x-(-5))+0.024845.*(x-(-5)).*(x-(-3.33333))+0.014945.*(x-(-5)).*(x-(-3.33333)).*(x-(-1.66667))-0.013170.*(x-(-5)).*(x-(-3.33333)).*(x-(-1.66667)).*(x-(0))+0.004203.*(x-(-5)).*(x-(-3.33333)).*(x-(-1.66667)).*(x-(0)).*(x-(1.66667))-0.000841.*(x-(-5)).*(x-(-3.33333)).*(x-(-1.66667)).*(x-(0)).*(x-(1.66667)).*(x-(3.33333));
plot(x,y);
hold on;

y=0.0384615+0.022343.*(x-(-5))+0.013956.*(x-(-5)).*(x-(-3.75))+0.011704.*(x-(-5)).*(x-(-3.75)).*(x-(-2.5))+0.000674.*(x-(-5)).*(x-(-3.75)).*(x-(-2.5)).*(x-(-1.25))-0.004896.*(x-(-5)).*(x-(-3.75)).*(x-(-2.5)).*(x-(-1.25)).*(x-(0))+0.002440.*(x-(-5)).*(x-(-3.75)).*(x-(-2.5)).*(x-(-1.25)).*(x-(0)).*(x-(1.25))-0.000687.*(x-(-5)).*(x-(-3.75)).*(x-(-2.5)).*(x-(-1.25)).*(x-(0)).*(x-(1.25)).*(x-(2.5))+0.000137.*(x-(-5)).*(x-(-3.75)).*(x-(-2.5)).*(x-(-1.25)).*(x-(0)).*(x-(1.25)).*(x-(2.5)).*(x-(3.75));
plot(x,y);
hold on;

y = 1./(1+x.^2);
plot(x,y,'black');
hold on;

legend('n=2','n=4','n=6','n=8','original');
title('B');

saveas(1,"../plot/B.jpg");
close(1);


%% C
x = -1:0.001:1;
y=0.0423498-0.169047.*(x-(0.951059))+1.425632.*(x-(0.951059)).*(x-(0.587808))+2.612336.*(x-(0.951059)).*(x-(0.587808)).*(x-(4.63268e-05))+2.746687.*(x-(0.951059)).*(x-(0.587808)).*(x-(4.63268e-05)).*(x-(-0.587733));
plot(x,y);
hold on;

y=0.0393883-0.088738.*(x-(0.987689))+0.189671.*(x-(0.987689)).*(x-(0.891013))-0.534253.*(x-(0.987689)).*(x-(0.891013)).*(x-(0.707123))+2.116588.*(x-(0.987689)).*(x-(0.891013)).*(x-(0.707123)).*(x-(0.454019))+8.285642.*(x-(0.987689)).*(x-(0.891013)).*(x-(0.707123)).*(x-(0.454019)).*(x-(0.156476))+11.949642.*(x-(0.987689)).*(x-(0.891013)).*(x-(0.707123)).*(x-(0.454019)).*(x-(0.156476)).*(x-(-0.156384))+10.349159.*(x-(0.987689)).*(x-(0.891013)).*(x-(0.707123)).*(x-(0.454019)).*(x-(0.156476)).*(x-(-0.156384)).*(x-(-0.453937))+5.503056.*(x-(0.987689)).*(x-(0.891013)).*(x-(0.707123)).*(x-(0.454019)).*(x-(0.156476)).*(x-(-0.156384)).*(x-(-0.453937)).*(x-(-0.707058))-0.010702.*(x-(0.987689)).*(x-(0.891013)).*(x-(0.707123)).*(x-(0.454019)).*(x-(0.156476)).*(x-(-0.156384)).*(x-(-0.453937)).*(x-(-0.707058)).*(x-(-0.890971));
plot(x,y);
hold on;

y=0.0388699-0.080067.*(x-(0.994522))+0.134959.*(x-(0.994522)).*(x-(0.951059))-0.231490.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033))+0.449126.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159))-1.047405.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159)).*(x-(0.587808))+2.339322.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159)).*(x-(0.587808)).*(x-(0.406768))+14.020809.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159)).*(x-(0.587808)).*(x-(0.406768)).*(x-(0.207951))+6.903338.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159)).*(x-(0.587808)).*(x-(0.406768)).*(x-(0.207951)).*(x-(4.63268e-05))-47.608730.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159)).*(x-(0.587808)).*(x-(0.406768)).*(x-(0.207951)).*(x-(4.63268e-05)).*(x-(-0.20786))-140.742124.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159)).*(x-(0.587808)).*(x-(0.406768)).*(x-(0.207951)).*(x-(4.63268e-05)).*(x-(-0.20786)).*(x-(-0.406683))-235.894350.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159)).*(x-(0.587808)).*(x-(0.406768)).*(x-(0.207951)).*(x-(4.63268e-05)).*(x-(-0.20786)).*(x-(-0.406683)).*(x-(-0.587733))-302.344227.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159)).*(x-(0.587808)).*(x-(0.406768)).*(x-(0.207951)).*(x-(4.63268e-05)).*(x-(-0.20786)).*(x-(-0.406683)).*(x-(-0.587733)).*(x-(-0.743097))-331.904566.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159)).*(x-(0.587808)).*(x-(0.406768)).*(x-(0.207951)).*(x-(4.63268e-05)).*(x-(-0.20786)).*(x-(-0.406683)).*(x-(-0.587733)).*(x-(-0.743097)).*(x-(-0.865987))-333.694907.*(x-(0.994522)).*(x-(0.951059)).*(x-(0.866033)).*(x-(0.743159)).*(x-(0.587808)).*(x-(0.406768)).*(x-(0.207951)).*(x-(4.63268e-05)).*(x-(-0.20786)).*(x-(-0.406683)).*(x-(-0.587733)).*(x-(-0.743097)).*(x-(-0.865987)).*(x-(-0.951031));
plot(x,y);
hold on;

y=0.0386905-0.077313.*(x-(0.996918))+0.120770.*(x-(0.996918)).*(x-(0.972372))-0.178927.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884))+0.271499.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649))-0.441430.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042))+0.785396.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467))-1.445485.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524))+1.114231.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716))+23.782396.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484))-24.192226.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484)).*(x-(0.078503))-331.584484.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484)).*(x-(0.078503)).*(x-(-0.0784106))-966.020031.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484)).*(x-(0.078503)).*(x-(-0.0784106)).*(x-(-0.233394))-1734.264090.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484)).*(x-(0.078503)).*(x-(-0.0784106)).*(x-(-0.233394)).*(x-(-0.38263))-2309.347852.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484)).*(x-(0.078503)).*(x-(-0.0784106)).*(x-(-0.233394)).*(x-(-0.38263)).*(x-(-0.522445))-2461.154524.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484)).*(x-(0.078503)).*(x-(-0.0784106)).*(x-(-0.233394)).*(x-(-0.38263)).*(x-(-0.522445)).*(x-(-0.649397))-2164.996856.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484)).*(x-(0.078503)).*(x-(-0.0784106)).*(x-(-0.233394)).*(x-(-0.38263)).*(x-(-0.522445)).*(x-(-0.649397)).*(x-(-0.760359))-1549.924445.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484)).*(x-(0.078503)).*(x-(-0.0784106)).*(x-(-0.233394)).*(x-(-0.38263)).*(x-(-0.522445)).*(x-(-0.649397)).*(x-(-0.760359)).*(x-(-0.8526))-785.383481.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484)).*(x-(0.078503)).*(x-(-0.0784106)).*(x-(-0.233394)).*(x-(-0.38263)).*(x-(-0.522445)).*(x-(-0.649397)).*(x-(-0.760359)).*(x-(-0.8526)).*(x-(-0.923849))+3.192065.*(x-(0.996918)).*(x-(0.972372)).*(x-(0.923884)).*(x-(0.852649)).*(x-(0.76042)).*(x-(0.649467)).*(x-(0.522524)).*(x-(0.382716)).*(x-(0.233484)).*(x-(0.078503)).*(x-(-0.0784106)).*(x-(-0.233394)).*(x-(-0.38263)).*(x-(-0.522445)).*(x-(-0.649397)).*(x-(-0.760359)).*(x-(-0.8526)).*(x-(-0.923849)).*(x-(-0.97235));
plot(x,y);
hold on;

y = 1./(1+25*x.^2);
plot(x,y,'black');
hold on;

title('C');
legend('n=5','n=10','n=15','n=20','original');
saveas(1,"../plot/C.jpg");
close(1);

%% D
clear;
x=0:0.001:13;
y = 0+75.000000.*(x-(0))+0.000000.*(x-(0)).*(x-(0))+0.222222.*(x-(0)).*(x-(0)).*(x-(3))-0.031111.*(x-(0)).*(x-(0)).*(x-(3)).*(x-(3))-0.006444.*(x-(0)).*(x-(0)).*(x-(3)).*(x-(3)).*(x-(5))+0.002264.*(x-(0)).*(x-(0)).*(x-(3)).*(x-(3)).*(x-(5)).*(x-(5))-0.000913.*(x-(0)).*(x-(0)).*(x-(3)).*(x-(3)).*(x-(5)).*(x-(5)).*(x-(8))+0.000131.*(x-(0)).*(x-(0)).*(x-(3)).*(x-(3)).*(x-(5)).*(x-(5)).*(x-(8)).*(x-(8))-0.000020.*(x-(0)).*(x-(0)).*(x-(3)).*(x-(3)).*(x-(5)).*(x-(5)).*(x-(8)).*(x-(8)).*(x-(13));
plot(x,y);
title('x');
saveas(1,"../plot/D_x.jpg");
close(1);

for i=1:(size(y,2)-1)
    v(i)=(y(i+1)-y(i))*1000; %用差分代替速度
end
v(i+1)=v(i);

plot(x,v);
hold on;
plot([0,13],[81,81],'red');

title('v');
legend('v','v=81');
saveas(1,"../plot/D_v.jpg");
close(1);

% i=10000时 x(i) = 10;即t 为10
"t=10时"
y(10000)
v(10000)

%% E
x= 0:0.01:28;
Sp_1=6.67+1.771667.*(x-(0))+0.457833.*(x-(0)).*(x-(6))-0.124778.*(x-(0)).*(x-(6)).*(x-(10))+0.013566.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13))-0.000978.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13)).*(x-(17))+0.000041.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13)).*(x-(17)).*(x-(20));
Sp_2 =6.67+1.571667.*(x-(0))-0.087167.*(x-(0)).*(x-(6))-0.015273.*(x-(0)).*(x-(6)).*(x-(10))+0.002579.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13))-0.000205.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13)).*(x-(17))+0.000009.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13)).*(x-(17)).*(x-(20));
plot(x,Sp_1);
title('Sp_1');
saveas(1,"../plot/Sp_1.jpg");
close(1);
plot(x,Sp_2);
title('Sp_2');
saveas(1,"../plot/Sp_2.jpg");
close(1);


x= 28:0.01:45;
Sp_1=6.67+1.771667.*(x-(0))+0.457833.*(x-(0)).*(x-(6))-0.124778.*(x-(0)).*(x-(6)).*(x-(10))+0.013566.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13))-0.000978.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13)).*(x-(17))+0.000041.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13)).*(x-(17)).*(x-(20));
Sp_2 =6.67+1.571667.*(x-(0))-0.087167.*(x-(0)).*(x-(6))-0.015273.*(x-(0)).*(x-(6)).*(x-(10))+0.002579.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13))-0.000205.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13)).*(x-(17))+0.000009.*(x-(0)).*(x-(6)).*(x-(10)).*(x-(13)).*(x-(17)).*(x-(20));
plot(x,Sp_1);
title('Sp_1');
saveas(1,"../plot/Sp_1_predict.jpg");
close(1);
plot(x,Sp_2);
title('Sp_2');
saveas(1,"../plot/Sp_2_predict.jpg");
close(1);